package com.leave.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 系统类
 *
 */
public class SystemServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 获取请求的方法
		String method = request.getParameter("method");

		if ("LoginOut".equals(method)) { // 退出系统
			loginOut(request, response);
		} else if ("toStudentView".equalsIgnoreCase(method)) { // 到学生界面
			request.getRequestDispatcher("/WEB-INF/jsp/student/student.jsp").forward(request, response);
		} else if ("toAdminView".equals(method)) { // 到辅导员界面
			request.getRequestDispatcher("/WEB-INF/jsp/assistant/assistant.jsp").forward(request, response);
		} else if ("toTeacherView".equals(method)) { // 到教师界面
			request.getRequestDispatcher("/WEB-INF/jsp/teacher/teacher.jsp").forward(request, response);
		} else if ("toAdminPersonalView".equals(method)) { // 到系统管理员系统设置界面
			request.getRequestDispatcher("/WEB-INF/view/admin/adminPersonal.jsp").forward(request, response);
		}
	}

	/**
	 * 退出系统
	 * 
	 * @param request
	 * @param response
	 * @throws IOException
	 * @throws ServletException
	 */
	private void loginOut(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 退出系统时清除系统登录的用户
		request.getSession().removeAttribute("user");
		String contextPath = request.getContextPath();
		// 转发到登录界面
		response.sendRedirect(contextPath + "/index.jsp");
	}

}
